#1.
# read -p "请输入数字1:" num1 
# read -p "请输入数字2:" num2

# if [ $num1 -gt $num2 ]
# then
#     echo "数字1大于数字2"
# elif [ $num1 -eq $num2 ]
# then
#     echo "数字1等于数字2"
# else
#     echo "数字1小于数字2"
# fi

# 2.
# read -p "请输入数字:" num
# if [ $((num%2)) -eq 0 ]
# then
#     echo "这个数是偶数"
# else
#     echo "这个数是奇数"
# fi

# 3.
# read -p "请输入年份:" years
# if [ $((years%400)) -eq 0 ]
# then
#     echo "这个年份是世纪闰年"
# elif [  $((years%100)) -ne 0 -a $((years%4)) -eq 0 ]
# then
#     echo "这个年份是闰年"
# else
#     echo "这个年份是平年"
# fi

# 4
# read -p "请输入第一个数" num1
# read -p "请输入第二个数" num2
# read -p "请输入第三个数" num3
# if [ $num1 -lt $num2 -a $num1 -lt $num3 -a $num2 -lt $num3 ] #1 2 3
# then
#     echo "$num1 $num2 $num3"
# elif [ $num1 -lt $num2 -a $num1 -lt $num3 -a $num2 -gt $num3 ] # 1 3 2
# then    
#     echo "$num1 $num3 $num2"
# elif [ $num1 -gt $num2 -a $num1 -lt $num3 -a $num2 -lt $num3 ] # 2 1 3
# then    
#     echo "$num2 $num1 $num3"
# elif [ $num1 -lt $num2 -a $num1 -gt $num3 -a $num2 -gt $num3 ] # 2 3 1
# then
#     echo "$num3 $num1 $num2"
# elif [ $num1 -gt $num2 -a $num1 -gt $num3 -a $num2 -gt $num3 ] # 3 2 1
# then
#     echo "$num3 $num2 $num1"
# else
# #elif [ $num1 -gt $num2 -a $num1 -gt $num3 -a $num2 -lt $num3 ] # 3 1 2
#     echo "$num2 $num3 $num1"
# fi

# 5.
# read -p "请输入一个路径下的文件:" fileinpath
# if [ -f $fileinpath ]
# then
#     cp /var/log/messages /root/
# else
#     echo "please check your file!"
# fi

#6.
#echo -p "我的名字叫$1,我的班级是$2班"

#7.
# read -p "请输入任意数字:" num
# if [ $num -eq 666 ]
# then 
#     echo "evil"
# elif [ $num -eq 777 ]
# then
#     echo "lucky"
# else
#     echo "human"
# fi

#8.
# read -p "请输入任意数字:" num
# case $num in
# "666")
# echo "evil"
# ;;
# "777")
# echo "lucky"
# ;;
# *)
# echo "human"
# ;;
# esac

#9.
# if [ -f /root/hosts ]
# then
#     date >> /root/hosts
# else
#     touch /root/hosts
# fi

#10.
# if [ "$USER" = "root" ]
# then
#     ifconfig
# else
#     echo "$USER非root账号"
# fi

#11
# read -p "请提供一个绝对路径的文件:" fileinpath
# if [ -f $fileinpath ]
# then
#     chmod a+x $fileinpath 
#     echo "添加执行权限成功"
# else
#     echo "没有传递文件"
# fi

#12
# n=`netstat -nltp | grep -c "3306"`
# if [ $n -gt 0 ]
# then
#     echo "mysql正常启动"
# else
#     echo "未找到mysql端口"
# fi

#13
# date
# read -p "请输入用户名:" yh
# if [ $((`cat /etc/passwd | grep -c "$yh"`)) -ge 1 ]
# then
#     echo "hello,$yh!"
# else   
#     echo "waiting for $yh!"
# fi

#14
# read -p "请输入一个目录:" folder
# if [ ! -d $folder ]
# then 
#     echo "不是目录"
# else
#     ls -l $folder
#     d1=`ls -l $folder | grep -c "^d"`
#     file=`ls -l $folder | grep -c "^-"`
#     echo "目录的数量:$folder"
#     echo "文件的数量:$file"
# fi


# 1.for i in `seq 20 2 40`
#     do
#         echo "$i"
#     done

#2.
# for i in `seq 50 -1 1`
#     do
#         echo "$i"
#     done

#3.
# for i in `seq 1 100`
#     do
#         if [ $(($i%2)) -ne 0 ]
#         then
#             sum=$(($sum+$i))
#         fi
#     done
#     echo "$sum"


#5.
# heads=35
# foots=94
# for ((chick=0; chick<=heads; chick++)) #鸡头的起始数量是0，并且35个头不能全是鸡，每次循环鸡头数量+1
#     do
#     rabbit=$(($heads-$chick)) #每次循环鸡头数量增加兔头数量就会减少，兔头数量=总头数-鸡头
#     sumfoot=$((2*$chick+4*$rabbit)) #每次循环鸡头数量加，兔头数量减时计算总脚数
#         if [ $sumfoot -eq $foots ] #当计算出的总脚数刚好等于题目给出的总脚数时输出结果
#         then
#             echo "鸡的数量:" $chick
#             echo "兔的数量:" $rabbit
#         fi
#     done

#6.
# i=9 #从第9天倒推第1天
# tao=1 #第10天早上剩1个
# while [ $i -ge 1 ]
#     do
#     tao=$(((tao+1)*2)) #计算前一天的桃子数
#     echo "第$i天有$tao个桃子"
#     i=$((i-1))
#     done

#7.
# groupadd wanmei
# i=1
# while [ `cat /etc/group | grep -c "wanmei"` -eq 1  ]
#     do 
#         useradd -g wanmei wm$i
#         if [ `cat /etc/passwd | grep -c "wm9"` -eq 1 ]
#         then
#             break
#         fi
#         i=$((i+1))
#     done

#8.
# i=1
# while [ `cat /etc/group | grep -c "wanmei"` -eq 1  ]
#     do 
#         userdel wm$i
#         if [ `cat /etc/passwd | grep -c "wm9"` -eq 0 ]
#         then
#             break
#         fi
#         i=$((i+1))
#     done
# groupdel wanmei

#9.
# read -p "请传入一个目录:" folder
# if [ -d $folder ]
# then
#     cd /$folder
#     ls -l
# else
#     echo "这不是一个目录"
# fi

#10.
# num2=$((RANDOM%99+1))
# while true
# do
#     read -p "请输入一个数字:" num1
#     if [ "$num1" -gt "$num2" ]
#     then
#         echo "太大了!"
#     elif [ "$num1" -lt "$num2" ]
#     then
#         echo "太小了!"
#     else
#         echo "猜对了!"
#         break
#     fi
# done

# read -p "请输入任意数字:" num
# if [ $num -eq 666 ]
# then
#  echo "evil"
# elif [ $num -eq 777 ]
# then
#  echo "lucky"
# else
#  echo "human"
# fi

# read -p "请输入任意数字:" num
# case $num in
# "666")
# echo "evil"
# ;;
# "777")
# echo "lucky"
# ;;
# *)
# echo "human"
# ;;
# esac


# read -p "请传入一个目录:" folder
# if [ -d $folder ]
# then
#  cd /$folder
#  names=`ls $folder`
#     for i in  $names
#         do
#             if [ -f $folder/$i ]
#             then
#             echo "$i"
#             fi
#         done
# else
#  echo "这不是一个目录"
# fi

#1.
# for i in `seq 1 9`
#     do
#         for j in `seq 1 $i`
#         do
#             echo  -n "$i*$j=$(($i*$j))  "
#         done
#         echo " "
#     done

#2.
# for i in `seq 1 5`
#     do
#         for j in `seq 1 $(($i*2-1))`
#         do
#             echo -n "*" #按照i的增长个数，每行输出多少个*
#         done
#         echo " " #控制多少行
#     done

#3.
# for i in `seq 1 5`
#     do
#         for k in `seq 1 $((5-$i))` #在每一行前面插入5-i个空格将*移后
#         do
#             echo -n " "
#         done
#         for j in `seq 1 $(($i*2-1))`
#         do
#             echo -n "*" #按照i的增长个数，每行输出多少个*
#         done
#         echo "1" #控制多少行
#     done
# &&&&*
# &&&***
# &&*****
# &*******
# *********

#4.
# #等腰三角形部分
# for i in `seq 1 5`
#     do
#         for k in `seq 1 $((5-$i))` #在每一行前面插入5-$i个空格将*移后
#         do
#             echo -n " "
#         done
#         for j in `seq 1 $(($i*2-1))`
#         do
#             echo -n "*" #按照i的增长个数，每行输出多少个*
#         done
#         echo " " #控制多少行
#     done
# #倒三角部分
# for i in `seq 1 4`
#     do
#         for k in `seq 1 $i` #在每一行前面插入$i个空格
#         do
#             echo -n " "
#         done
#         for j in `seq 1 $((9-($i*2)))` #因为是倒序，所以会从7开始（两个三角形之间的分隔行9个*已经由等腰三角形部分形成），以$i为变量调整*的数量
#         do
#             echo -n "*" 
#         done
#         echo " " #控制倒三角部分有多少行
#     done

# &&&&*
# &&&***
# &&*****
# &*******
# *********
# &*******
# &&*****
# &&&***
# &&&&*


#5.
# count=0
# for i in `seq 100 200` #取100-200之间的整数
#     do
#         for j in `seq 2 $(($i-1))` #每个数都能被1和自己整除，依次去除于2..自身-1的数
#         do
#             result=$(($i%$j)) #取自身与2..自身-1的取余结果
#             if [ $result -eq 0 ] #若结果等于0则打破循环，说明不是素数
#             then
#                 break
#             elif [ $j -eq $(($i-1)) ] #遍历2..自身-1的数相除之后，若得到数已经等于自身-1这个数，则说明这个数是素数
#             then
#                 echo "$i是素数"
#                 count=$(($count+1)) #登录素数的数量，每有一个就+1
#             fi
#         done
#     done
#     echo "$count" #输出素数的总数量

#1.
# function getProduct(){
#     product=$(($1*$2*$3))
#     echo "$product"
# }

#     read -p "请输入第一个数:" num1
#     read -p "请输入第二个数:" num2
#     read -p "请输入第三个数:" num3
# getProduct $num1 $num2 $num3

#2.
# function getPlus(){
#     pp=$(($1+($1-1)+($1-2)+($1-3)+($1-4)))
#     echo "和是:$pp"
# }

# read -p "请输入一个数:" num1
# getPlus $num1
# function getPlus(){
#     num1=$1
#     sum=0
#     for i in `seq 0 1 $num1`
#         do
#             sum=$(($sum+$i))
#         done
#     echo "$num1的累加是$sum"
# }
# read -p "请输入一个数:" n1
# getPlus $n1


#3.
# function judge(){
#     if [ $# -eq 0 -o $# -gt 2 ]
#     then
#         echo "-1"
#     elif [ $# -eq 1 ]
#     then
#         echo "1"
#     else
#         echo "2"
#     fi
# }

# judge 1
# judge 1 2
# judge 1 2 3 
# judge 1 2 3 4

#4.
# function getFile(){
#     folder=$1
#     if [ -d $folder ] #输入的路径是否为目录，是则进入循环
#     then
#         for i in $folder/* #使用i遍历$folder路径下的所有目录和文件，
#         # /*表示的是将$folder路径下所有的文件夹以及文件以绝对路径的方式罗列出来以供下面的if循环做判断，这也是下面的if循环中能够将getFile嵌套使用的关键
#             do
#                 if [ -f $i ] #判断$i是否是文件
#                 then
#                     echo $i #$i是文件，则打印对应文件的名字
#                 elif [ -d $i ] #判断$i是否是目录
#                 then
#                     getFile $i #$i是目录，返回循环继续对其他目录或者文件进行判断
#                 fi
#             done
#     else
#         echo "这不是一个目录" #输入的路径不是目录，退出循环
#     fi
# }
# read -p "请输入一个目录路径:" path
# getFile $path

# read -p "请输入一个目录路径:" path
# getFile $path

#5.
# function getFac(){
#     num1=$1
#     fac=1
#             for i in `seq 1 1 $num1`
#             do
#                 fac=$(($fac*$i))
#             done 
#         echo "$num1的阶乘是$fac"
# }
# read -p "请输入一个数:" num
# getFac $num



# 输入一个目录显示里面的所有目录
# fun(){
# for i in `ls $1`
# do
# if [ -d $1/$i ]
# then
# echo $i
# fi
# done
# }
# fun /root
# # 输入一个目录显示里面的所有目录及其子目录
# echo $i
# fun $1/$i




# 无输入无返回
# hello(){
# echo "test"
# }
# hello
# #写一个自定义函数，计算两个输入参数的和
# he(){
# s=0
# s=$(($1 + $2))
# echo "$s"
# }
# he 3 65
# jieguo=`he 3 65`
# echo "和是：$jieguo"